load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_binary")
load("@com_github_grpc_grpc_kotlin//:kt_jvm_grpc.bzl", "kt_jvm_grpc_library", "kt_jvm_proto_library")

# We need to create a separate proto_library
# to conform with macro java_proto_library rules
proto_library(
    name = "service_proto_v1alpha1",
    srcs = ["src/main/proto/v1alpha1/service.proto"],
    deps = [
        "@com_google_protobuf//:struct_proto",
        "@com_google_protobuf//:wrappers_proto",
    ],
)

java_proto_library(
    name = "service_java_proto_v1alpha1",
    deps = [":service_proto_v1alpha1"],
)

kt_jvm_proto_library(
    name = "service_kt_proto_v1alpha1",
    deps = [":service_proto_v1alpha1"],
)

kt_jvm_grpc_library(
    name = "service_kt_grpc_v1alpha1",
    srcs = [":service_proto_v1alpha1"],
    deps = [":service_java_proto_v1alpha1"],
)

kt_jvm_binary(
    name = "client",
    srcs = ["src/main/kotlin/com/client/BentoServiceClient.kt"],
    main_class = "com.client.BentoServiceClient",
    deps = [
        ":service_kt_grpc_v1alpha1",
        ":service_kt_proto_v1alpha1",
        "@com_google_protobuf//:protobuf_java_util",
        "@io_grpc_grpc_java//netty",
    ],
)

proto_library(
    name = "service_proto",
    srcs = ["src/main/proto/v1/service.proto"],
    deps = [
        "@com_google_protobuf//:struct_proto",
        "@com_google_protobuf//:wrappers_proto",
    ],
)

java_proto_library(
    name = "service_java_proto",
    deps = [":service_proto"],
)

kt_jvm_proto_library(
    name = "service_kt_proto",
    deps = [":service_proto"],
)

kt_jvm_grpc_library(
    name = "service_kt_grpc",
    srcs = [":service_proto"],
    deps = [":service_java_proto"],
)

kt_jvm_binary(
    name = "client",
    srcs = ["src/main/kotlin/com/client/BentoServiceClient.kt"],
    main_class = "com.client.BentoServiceClient",
    deps = [
        ":service_kt_grpc",
        ":service_kt_proto",
        "@com_google_protobuf//:protobuf_java_util",
        "@io_grpc_grpc_java//netty",
    ],
)
